Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

stubs

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stubs

Easy method stubber.

  • 1.1.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

stubs

It's a simple stubber.

About

For when you don't want to write the same thing over and over to cache a method and call an override, then revert it, and blah blah.

Use

$ npm install --save-dev stubs
var mylib = require('./lib/index.js')
var stubs = require('stubs')

// make it a noop
stubs(mylib, 'create')

// stub it out
stubs(mylib, 'create', function() {
  // calls this instead
})

// stub it out, but call the original first
stubs(mylib, 'create', { callthrough: true }, function() {
  // call original method, then call this
})

// use the stub for a while, then revert
stubs(mylib, 'create', { calls: 3 }, function() {
  // call this 3 times, then use the original method
})

API

stubs(object, method[[, opts], stub])

object
  • Type: Object
method
  • Type: String

Name of the method to stub.

opts
  • (optional)
  • Type: Object
opts.callthrough
  • (optional)
  • Type: Boolean
  • Default: false

Call the original method as well as the stub (if a stub is provided).

opts.calls
  • (optional)
  • Type: Number
  • Default: 0 (never revert)

Number of calls to allow the stub to receive until reverting to the original.

stub
  • (optional)
  • Type: Function
  • Default: function() {}

This method is called in place of the original method. If opts.callthrough is true, this method is called after the original method is called as well.

Keywords

FAQs

Package last updated on 17 Oct 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc